<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			// var sortArrayByParity = function(A) {
			//     return A.sort((a, b) => (a & 1) - (b & 1))
			// };
			var sortArrayByParity = function(A) {
				let result = new Array(A.length);
				let l = 0;
				let	r = A.length - 1;
				for (let i = 0; i < A.length; i++) {
					if (A[i] % 2 == 0) {
						result[l] = A[i];
						l++;
					} else {
						result[r] = A[i];
						r--;
					}
				}
				return result;
			};
			console.log(sortArrayByParity([3, 1, 2, 4]));
		</script>
	</body>
</html>
